<?php
namespace app\api\service;
use think\Service;
use app\admin\model\admin;
class adminService
{
    static function withdrawal($uid = 0,$money = 0,$admin_id = 0)
    {   
        if($admin_id && $money){
        	$balance = Admin::where("id",$admin_id)->value("balance");
        	if($balance < $money){
        		 return ['code'=>100,'msg'=>'余额不足'];
        	}
            // 获取今天的开始和结束时间戳
            $startOfDay = strtotime('today');
            $endOfDay = strtotime('tomorrow') - 1;

            $find = Withdrawal::where('timestamp', 'between', [$startOfDay, $endOfDay])->find();
            if($find){
                  return ['code'=>100,'msg'=>'今日已提交审核'];
            }
            $r =  Withdrawal::create([
                'uid'=>$uid,
                'money'=>$money,
                'admin_id'=>$admin_id
            ]);
            if($r){
                 return ['code'=>200,'msg'=>'ok'];
            }else{
                 return ['code'=>100,'msg'=>'申请失败，请稍后重试'];
            }
        } 
        return ['code'=>100,'msg'=>'error!'];
    }
}